﻿using Practice.Common.DbCont;
using Practice.Common.Infrastructure.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Practice.Common.Infrastructure.Repositories
{
    public class BaseRepository<T> : IBaseRepository<T> where T : class,new()
    {
         public readonly EFDbContext db;

        public BaseRepository(EFDbContext db)
        {
            this.db = db;
        }

        public int Add(T entity)
        {
            db.Set<T>().Add(entity);
            return db.SaveChanges();
        }

        public IQueryable<T> GetAll()
        {
            return db.Set<T>().AsQueryable();
        }

        public int Update(T entity)
        {
            db.Set<T>().Update(entity);
            return db.SaveChanges();
        }
    }
}
